#include "bitmapblock.h"

#define BOX_WIDTH 600
#define BOX_HEIGHT 200

BitmapBlock::BitmapBlock(QWidget *parent) :
    QWidget(parent),
    m_scrollBarValue(0)
{
}

BitmapBlock::~BitmapBlock()
{
}

void BitmapBlock::paintEvent(QPaintEvent *) {
    QPainter paint(this);
    QColor itemColor;

    int posX = 0, posY = 0;

    for (int i=m_scrollBarValue*50; i<NB_DATA_BLOCK; ++i) {
        int status = bitmap_block_get_status(i);

        if (status == BM_FREE) itemColor.setRgb(0, 192, 0);
        else if (status == BM_OCCUPIED) itemColor.setRgb(255, 0, 0);
        else itemColor.setRgb(0, 0, 0);

        paint.setPen(itemColor);
        paint.setBrush(QBrush(itemColor,Qt::SolidPattern));
        paint.drawRect(posX, posY, 10, 10);

        posX += 12;
        if ((i+1)%50 == 0) {
            posX = 0;
            posY += 12;
        }
    }

    paint.end();
}

void BitmapBlock::setScrollBarValue(int value) {
    m_scrollBarValue = value;
    this->update();
}
